import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/firestore'
import 'firebase/storage'

const firebaseConfig = {
  apiKey: 'AIzaSyBJeqagW4olK9nwhxeWhtB5wjT26rqGkOc',
  authDomain: 'music-d1dd2.firebaseapp.com',
  projectId: 'music-d1dd2',
  storageBucket: 'music-d1dd2.appspot.com',
  messagingSenderId: '291853646654',
  appId: '1:291853646654:web:af9a176859e3a7238e0a6f'
}
// 这玩意还要翻墙才能连上

// Initialize Firebase
firebase.initializeApp(firebaseConfig)
// 认证
const auth = firebase.auth()
// 数据库
const db = firebase.firestore()
//类似 oss
const storage = firebase.storage()

// 数据库---user这个表
const usersCollection = db.collection('users')
const songsCollection = db.collection('songs')
const commentsCollection = db.collection('comments')

// 这个库配合pwa做的浏览器数据库备份缓存 （上传不行）
db.enablePersistence().catch((err) => {
  console.log(`Firebase persistence error ${err.code}`)
})

export { auth, db, storage, usersCollection, songsCollection, commentsCollection }
